// Please don't remove line below - it is used for code-completion for Visual Studio
/// <reference path="preview\vsdoc.js" />
/// <reference path="BBCProgrammesAPI.js" />

// Reference to the WRTKit user interface manager and main view.
var uiManager;
var mainView;

// Reference to controls in the main view.
var helloButton;
var nameField;

//about view label control
var aboutLabel, bbcCopyright, blueghostInfo;

// Constants for menu item identifiers.
var MENU_ITEM_ABOUT = 0;

// Called from the onload event handler to initialize the widget.
function init() {
    //create about menu
    var aboutMenuItem = new MenuItem("About", MENU_ITEM_ABOUT);
    aboutMenuItem.onSelect = menuItemSelected;
    menu.append(aboutMenuItem);

    // set tab-navigation mode and show softkeys
    // (only if we are in the WRT environment)
    if (window.widget) {
        widget.setNavigationEnabled(false);
        menu.showSoftkeys();
    }

    // create UI manager
    uiManager = new UIManager();

    // create main view
    mainView = new ListView(null, "BBC Schedules");

    //Create about view
    aboutView = new ListView(null, "About BBC Schedules");

    // About label control
    aboutLabel = new Label();
    bbcCopyright = new Label();
    blueghostInfo = new Label();
    aboutView.addControl(blueghostInfo);
    aboutView.addControl(bbcCopyright);
    aboutView.addControl(aboutLabel);

    // display the main view
    uiManager.setView(mainView);
    initBBCProgrammesApi();
}

// Show main view.
function showMainView() {

    // set right softkey to "exit"
    if (window.widget) {
        menu.setRightSoftkeyLabel("", null);
    }

    // show the main view
    uiManager.setView(mainView);
}

// Callback for when menu items are selected.
function menuItemSelected(id) {
    switch (id) {
        case MENU_ITEM_ABOUT:
            showAboutView();
            break;
    }
}

//Displays the About view
function showAboutView() {
    blueghostInfo.setText('http://www.blueghosttv.co.uk/nokia/');
    bbcCopyright.setText('supported by backstage.bbc.co.uk');
    aboutLabel.setText('This Widget includes software licensed from Nokia &copy 2008');

    setAboutViewSoftkeys();
    uiManager.setView(aboutView);
}

// Sets the soft keys for about view.
function setAboutViewSoftkeys() {
    if (window.widget) {
        // set right soft key to "Ok" (returns to main view)
        menu.setRightSoftkeyLabel("Ok", showMainView);
    }
}